<div class="easyui-layout" data-options="fit:true">
	<!--<div data-options="region:'west',border:true,split:true," title="分类管理" style="width:150px; padding:5px;">
        <ul id="wu-category-tree" class="easyui-tree"></ul>
    </div>-->
	<!-- Begin of toolbar -->
	<div id="wu-toolbar-2">
		<div class="wu-toolbar-button">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="openAdd()" plain="true">添加</a>
		</div>
		<form>
			<div class="wu-toolbar-search">
				<label>供应商名称：</label><input id="sname" class="wu-text" style="width:100px">
				<label>供应商电话：</label><input id="sphone" class="wu-text" style="width:100px">
				<a href="#" class="easyui-linkbutton" onclick="selectBusiness()" iconCls="icon-search">开始检索</a>
			</div>
		</form>
	</div>
	<!-- End of toolbar -->
	<table id="wu-datagrid-2" class="easyui-datagrid" toolbar="#wu-toolbar-2"></table>
</div>
<!-- Begin of easyui-dialog -->
<div id="wu-dialog-23" class="easyui-dialog" title="添加信息" data-options="closed:true,iconCls:'icon-save'" style="width:400px; padding:10px;">
	<form id="wu-form-23" method="post">
		<table>
			<tr>
				<td width="80" align="right">供应商名称:</td>
				<td><input type="text" name="sname" class="wu-text" /></td>
			</tr>
			<tr>
				<td align="right">供应商账户:</td>
				<td><input type="text" name="saccount" class="wu-text" /></td>
			</tr>
			<tr>
				<td align="right">供应商电话:</td>
				<td><input type="text" name="sphone" class="wu-text" /></td>
			</tr>
		</table>
	</form>
	<div style="text-align:center;padding:5px">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addSaveUser()">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearAddUserForm()">清空</a>
	</div>
</div>
<div id="wu-dialog-2" class="easyui-dialog" title="修改信息" data-options="closed:true,iconCls:'icon-save'" style="width:400px; padding:10px;">
	<form id="wu-form-2" method="post">
		<table>
			<input type="text" hidden="hidden" name="supplierid" class="wu-text" />
			<tr>
				<td width="80" align="right">供应商名称:</td>
				<td><input type="text" name="sname" class="wu-text" /></td>
			</tr>
			<tr>
				<td align="right">供应商账户:</td>
				<td><input type="text" name="saccount" class="wu-text" /></td>
			</tr>
			<tr>
				<td align="right">供应商电话:</td>
				<td><input type="text" name="sphone" class="wu-text" /></td>
			</tr>
		</table>
	</form>
	<div style="text-align:center;padding:5px">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="updateSaveUser()">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearUptateUserForm()">清空</a>
	</div>
</div>
<!-- End of easyui-dialog -->
<script type="text/javascript">
	/**
	 * 页面加载事件
	 */
	$(function() {
		setTimeout(function() {
			selectBusiness();
		}, 1000);
	})

	/*查询所有用户信息*/
	function selectBusiness() {
		$('#wu-datagrid-2').datagrid({
			url: globalData.server + "supplier/selectSupplier",
			queryParams: {
				token: globalData.getToken(),
				sname: $("#sname").val(),
				sphone: $("#sphone").val()
			},
			onLoadSuccess: function(data) {
				$("a[name='sc']").linkbutton(({
					text: "删除",
					iconCls: "icon-remove",
					//plain: true
				})), $("a[name='bj']").linkbutton(({
					text: "编辑",
					iconCls: "icon-edit",
					//plain: true
				}))
			},
			rownumbers: true,
			pageSize: 4,
			pageList: [4, 6, 8, 10],
			pagination: true,
			multiSort: true,
			fitColumns: true,
			fit: true,
			columns: [
				[{
					field: 'text',
					title: '供应商名称',
					width: 80
				}, {
					field: 'saccount',
					title: '供应商账户',
					width: 80
				}, {
					field: 'sphone',
					title: '供应商电话',
					width: 80
				}/*,{
					field: 'supplierfatherid',
					title: '主供应商',
					width: 80
				}*/, {
					field: 'caozuo',
					title: '修改操作',
					width: 50,
					formatter: uupdate
				}, {
					field: 'caozuo1',
					title: '删除操作',
					width: 50,
					formatter: udelete
				}, ]
			]
		});
	}

	function uupdate(value, row, index) {
		return "<a class='easyui-linkbutton' name='bj'  onclick='uupdates(" + index +
			")'>修改信息</a>"
	}

	function udelete(value, row, index) {
		return "<a   class='easyui-linkbutton' name='sc'  onclick='udeletes(" + index +
			")'>删除信息</a>"
	}

	/**
	 * Name 删除记录
	 */
	function udeletes(index) {
		$.messager.confirm('信息提示', '确定要删除该记录？', function(result) {
			if(result) {
				var data = $('#wu-datagrid-2').datagrid('getData');
				var ids = data.rows[index].supplierid
					//alert(ids);return;
				$.ajax({
					url: globalData.server + 'supplier/deleteSupplier?token=' + globalData.getToken() + "&supplierid=" + ids,
					type: "post",
					dataType: 'json',
					success: function(res) {
						if(res > 0) {
							$.messager.alert('信息提示', '删除成功！', 'info');
							$("#wu-datagrid-2").datagrid("reload");
						} else {
							$.messager.alert('信息提示', '删除失败！', 'info');
						}
					}
				});
			}
		});
	}
	/**
	 * 回显修改框
	 */
	var updateUid;

	function uupdates(index) {
		var data = $("#wu-datagrid-2").datagrid("getData");
		var row = data.rows[index]; //获取验第index行对应的json数据
		updateUid = row.supplierid
		$("#wu-form-2").form("load", row);
		$("#wu-dialog-2").window("open");
	}
	//保存修改
	function updateSaveUser() {
		$.messager.confirm('提示', '确认修改吗?', function(r) {
			if(r) {
				$.post(
					globalData.server + "supplier/updateSupplier?token=" + globalData.getToken(),
					$("#wu-form-2").serialize(),
					function(res) {
						if(res == 0) {
							$.messager.alert('提示', "修改失败");
						} else {
							$.messager.alert('提示', "修改成功");
							$("#wu-dialog-2").window("close");
							$("#wu-datagrid-2").datagrid("reload");
						}
					}, "json");
			}

		});

	}
	//打开添加框
	function openAdd() {
		$("#wu-form-23").form("clear");
		$("#wu-dialog-23").window("open"); //打开窗口
	}
	//保存添加框
	function addSaveUser() {
		$.messager.confirm('提示', '确认添加吗?', function(r) {
			if(r) {
				$.post(
					globalData.server + "supplier/insertSupplier?token=" + globalData.getToken(),
					$("#wu-form-23").serialize(),
					function(res) {
						if(res.success == false) {
							$.messager.alert('提示', "添加失败");
							return;
						} else {
							$.messager.alert('提示', "添加成功");
							$("#wu-dialog-23").window("close");
							$("#wu-datagrid-2").datagrid("reload");
						}
					}, "json");
			}

		});

	}
</script>